﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using SmartProject.Data;
using System.Data;

namespace SmartProject.BusinessObjects
{
    public class UserMessage : Entity
    {
        private ViewStatus _viewStatus;

        public UserMessage()
        {
            DataParameter[] dataParameters = new DataParameter[3];
            dataParameters[0] = new DataParameter("UserId", DataType.Integer);
            dataParameters[1] = new DataParameter("MessageId", DataType.Integer);
            dataParameters[2] = new DataParameter("ViewStatusId", DataType.Integer);
            _viewStatus = new ViewStatus();
            base.Initialize(dataParameters);
        }

        public ViewStatus ViewStatus
        {
            get { return _viewStatus; }
        }

        public override void Load()
        {
            throw new NotImplementedException();
        }

        public override void Save()
        {
            int unreadId = _viewStatus.GetId("Unread", false);
            base.SetAttribute("ViewStatusId", unreadId);
            base.Run("smartProject_AddUserMessage");
        }

        public System.Data.DataTable LoadUnReadUserMessages()
        {
            base.SetAttribute("ViewStatusId", _viewStatus.GetId("Unread", false));
            return base.Find("smartProject_GetUserMessages");
        }

        public override void Update()
        {
            base.SetAttribute("ViewStatusId", _viewStatus.GetId("Viewed", false));
            base.Run("smartProject_UpdateUserMessage");
        }

        public override void Remove()
        {
            base.Run("smartProject_RemoveUserMessage");
        }
    }
}
